<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="APP,iOS,Android,Cordova,Angular2,Ionic2," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="概述Ionic2的代码工程结构区别于Ionic1.x，其结构更加简单清晰，便于维护和管理。Ionic2采用webpack和gulp管理编译及打包。">
<meta property="og:type" content="article">
<meta property="og:title" content="Hybrid混合开发实践-Cordova/Angular2/Ionic2-工程结构(3)">
<meta property="og:url" content="http://chrisrc.me/2016/03/12/hybrid-cordova-angular2-ionic2-practice-3/index.html">
<meta property="og:site_name" content="山中，山外与俯瞰">
<meta property="og:description" content="概述Ionic2的代码工程结构区别于Ionic1.x，其结构更加简单清晰，便于维护和管理。Ionic2采用webpack和gulp管理编译及打包。">
<meta property="og:image" content="http://chrisrc.me/images/ionic_chrome_debug.png">
<meta property="og:updated_time" content="2016-12-17T07:29:29.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Hybrid混合开发实践-Cordova/Angular2/Ionic2-工程结构(3)">
<meta name="twitter:description" content="概述Ionic2的代码工程结构区别于Ionic1.x，其结构更加简单清晰，便于维护和管理。Ionic2采用webpack和gulp管理编译及打包。">
<meta name="twitter:image" content="http://chrisrc.me/images/ionic_chrome_debug.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://chrisrc.me/2016/03/12/hybrid-cordova-angular2-ionic2-practice-3/"/>





  <title> Hybrid混合开发实践-Cordova/Angular2/Ionic2-工程结构(3) | 山中，山外与俯瞰 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">山中，山外与俯瞰</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">一次永不停止的探索之旅</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-dcos">
          <a href="/dcos" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            DC/OS
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="st-search-show-outputs">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <form class="site-search-form">
  <input type="text" id="st-search-input" class="st-search-input st-default-search-input" />
</form>

<script type="text/javascript">
  (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
    (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
    e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
  })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');

  _st('install', 'R9GcmhBwxpsAGLNCsquZ','2.0.0');
</script>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://chrisrc.me/2016/03/12/hybrid-cordova-angular2-ionic2-practice-3/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="chrisrc">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.gif">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="山中，山外与俯瞰">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="山中，山外与俯瞰" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Hybrid混合开发实践-Cordova/Angular2/Ionic2-工程结构(3)
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2016-03-12T10:10:18+08:00">
                2016-03-12
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/移动端/" itemprop="url" rel="index">
                    <span itemprop="name">移动端</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <a href="/2016/03/12/hybrid-cordova-angular2-ionic2-practice-3/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/03/12/hybrid-cordova-angular2-ionic2-practice-3/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h2><p>Ionic2的代码工程结构区别于Ionic1.x，其结构更加简单清晰，便于维护和管理。Ionic2采用webpack和gulp管理编译及打包。</p>
<a id="more"></a>
<h2 id="代码结构"><a href="#代码结构" class="headerlink" title="代码结构"></a>代码结构</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div></pre></td><td class="code"><pre><div class="line">myapp</div><div class="line">    |----app</div><div class="line">    |      |----app.js              APP入口，存放设备初始化等逻辑代码</div><div class="line">    |      |----pages               页面逻辑代码存放位置</div><div class="line">    |      |        |----tabs       存放TAB导航菜单（位于底部或顶部）</div><div class="line">    |      |        |----page1      功能页面</div><div class="line">    |      |                |----page1.html     存放页面视图布局定义</div><div class="line">    |      |                |----page1.js       存放页面视图控制逻辑实现</div><div class="line">    |      |                |----page1.scss     存放页面视图的样式定义 （该文件必须在app.core.scss中声明引用）</div><div class="line">    |      |        |---- ......</div><div class="line">    |      |        |----components  存放自定义控件</div><div class="line">    |      |                |----comp1</div><div class="line">    |      |                        |----cpage1.html</div><div class="line">    |      |                        |----cpage1.js</div><div class="line">    |      |                        |----cpage1.scss</div><div class="line">    |      |----services    存放服务实现逻辑</div><div class="line">    |               |----config.js</div><div class="line">    |               |----util.js</div><div class="line">    |               |---- ......</div><div class="line">    |      |----theme                       全局样式定义</div><div class="line">    |               |----app.core.scss      核心样式（同时适用于ios、android和wp）</div><div class="line">    |               |----app.ios.scss       ios特定样式（仅适用于ios）</div><div class="line">    |               |----app.md.scss        android特定样式（仅适用于android）</div><div class="line">    |               |----app.variables.scss</div><div class="line">    |       </div><div class="line">    |----hooks      HOOK定义，用于自定义cordova编译过程</div><div class="line">    |       </div><div class="line">    |----node_modules   开发所依赖的npm组件</div><div class="line">                |---- ......</div><div class="line">                |----ionic-angular      Ionic 2 源代码</div><div class="line">                |----ionic-native       Ionic 2 封装第三方插件的组件代码</div><div class="line">                |---- ......</div><div class="line">    |</div><div class="line">    |----plugins    cordova native插件存放目录</div><div class="line">            |---- ionic-plugin-keyboard   键盘处理插件</div><div class="line">            |---- cordova-plugin-statusbar  顶部状态栏插件</div><div class="line">            |---- ......</div><div class="line">    |----resources  APP打包资源存放目录（存放logo、splashscreen等）</div><div class="line">    |----www    </div><div class="line">    |       |---- index.html    APP页面入口</div><div class="line">    |       |---- build         编译输出的：js、css、fonts、page等</div><div class="line">    |       |---- images        自定义资源存放</div><div class="line">    |       |---- data          自定义资源存放</div><div class="line">    |</div><div class="line">    |----config.xml     存放APP ID，版本，功能参数定义，该文件的配置直接影响APP的功能，后续会详细介绍。</div><div class="line">    |----package.json   存放JS依赖定义</div><div class="line">    |----gulpfile.js    定义代码编译过程</div><div class="line">    |----ionic.config.json 存放工程名，工程APP ID等ionic工程信息</div><div class="line">    |---- ......</div></pre></td></tr></table></figure>
<p>上述代码结构中的<code>app</code>和<code>www</code>可以代码结构可以根据项目特点和复杂度自行定义控制。</p>
<h2 id="工程配置"><a href="#工程配置" class="headerlink" title="工程配置"></a>工程配置</h2><h3 id="package-json"><a href="#package-json" class="headerlink" title="package.json"></a>package.json</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">  <span class="attr">"dependencies"</span>: &#123;</div><div class="line">    <span class="attr">"angular2"</span>: <span class="string">"2.0.0-beta.15"</span>,</div><div class="line">    <span class="attr">"es6-shim"</span>: <span class="string">"^0.35.0"</span>,</div><div class="line">    <span class="attr">"ionic-angular"</span>: <span class="string">"2.0.0-beta.6"</span>,</div><div class="line">    <span class="attr">"ionic-native"</span>: <span class="string">"^1.1.0"</span>,</div><div class="line">    <span class="attr">"ionicons"</span>: <span class="string">"3.0.0"</span>,</div><div class="line">    <span class="attr">"rxjs"</span>: <span class="string">"5.0.0-beta.2"</span></div><div class="line">  &#125;,</div><div class="line">  <span class="attr">"devDependencies"</span>: &#123;</div><div class="line">    <span class="attr">"del"</span>: <span class="string">"2.2.0"</span>,</div><div class="line">    <span class="attr">"gulp"</span>: <span class="string">"3.9.1"</span>,</div><div class="line">    <span class="attr">"gulp-watch"</span>: <span class="string">"4.3.5"</span>,</div><div class="line">    <span class="attr">"ionic-gulp-browserify-es2015"</span>: <span class="string">"^1.1.0"</span>,</div><div class="line">    <span class="attr">"ionic-gulp-fonts-copy"</span>: <span class="string">"^1.0.0"</span>,</div><div class="line">    <span class="attr">"ionic-gulp-html-copy"</span>: <span class="string">"^1.0.0"</span>,</div><div class="line">    <span class="attr">"ionic-gulp-sass-build"</span>: <span class="string">"^1.0.0"</span>,</div><div class="line">    <span class="attr">"ionic-gulp-scripts-copy"</span>: <span class="string">"^1.0.1"</span>,</div><div class="line">    <span class="attr">"run-sequence"</span>: <span class="string">"1.1.5"</span></div><div class="line">  &#125;,</div><div class="line">  <span class="attr">"cordovaPlugins"</span>: [</div><div class="line">    <span class="string">"cordova-plugin-device"</span>,</div><div class="line">    <span class="string">"cordova-plugin-console"</span>,</div><div class="line">    <span class="string">"cordova-plugin-whitelist"</span>,</div><div class="line">    <span class="string">"cordova-plugin-splashscreen"</span>,</div><div class="line">    <span class="string">"cordova-plugin-statusbar"</span>,</div><div class="line">    <span class="string">"ionic-plugin-keyboard"</span></div><div class="line">  ],</div><div class="line">  <span class="attr">"cordovaPlatforms"</span>: [</div><div class="line">    <span class="string">"ios"</span>,</div><div class="line">    &#123;</div><div class="line">      <span class="attr">"platform"</span>: <span class="string">"ios"</span>,</div><div class="line">      <span class="attr">"version"</span>: <span class="string">""</span>,</div><div class="line">      <span class="attr">"locator"</span>: <span class="string">"ios"</span></div><div class="line">    &#125;</div><div class="line">  ],</div><div class="line">  <span class="attr">"name"</span>: <span class="string">"myapp2"</span>,</div><div class="line">  <span class="attr">"description"</span>: <span class="string">"myapp2: An Ionic project"</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>该配置文件中的<code>name</code>，<code>description</code>，<code>dependencies</code>和<code>devDependencies</code>可以手动调整。 <code>cordovaPlugins</code>通过<code>ionic plugin add/rm</code>自动调整。 <code>cordovaPlatforms</code>通过<code>ionic platform add/rm</code>自动调整。</p>
<h3 id="config-xml"><a href="#config-xml" class="headerlink" title="config.xml"></a>config.xml</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line">&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;</div><div class="line"><span class="tag">&lt;<span class="name">widget</span> <span class="attr">id</span>=<span class="string">"com.ionicframework.myapp2941852"</span> <span class="attr">version</span>=<span class="string">"0.0.1"</span> <span class="attr">xmlns</span>=<span class="string">"http://www.w3.org/ns/widgets"</span> <span class="attr">xmlns:cdv</span>=<span class="string">"http://cordova.apache.org/ns/1.0"</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">name</span>&gt;</span>myapp2<span class="tag">&lt;/<span class="name">name</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">description</span>&gt;</span>An Ionic Framework and Cordova project.<span class="tag">&lt;/<span class="name">description</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">author</span> <span class="attr">email</span>=<span class="string">"hi@ionicframework"</span> <span class="attr">href</span>=<span class="string">"http://ionicframework.com/"</span>&gt;</span>Ionic Framework Team<span class="tag">&lt;/<span class="name">author</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">content</span> <span class="attr">src</span>=<span class="string">"index.html"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">access</span> <span class="attr">origin</span>=<span class="string">"*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-intent</span> <span class="attr">href</span>=<span class="string">"http://*/*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-intent</span> <span class="attr">href</span>=<span class="string">"https://*/*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-intent</span> <span class="attr">href</span>=<span class="string">"tel:*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-intent</span> <span class="attr">href</span>=<span class="string">"sms:*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-intent</span> <span class="attr">href</span>=<span class="string">"mailto:*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-intent</span> <span class="attr">href</span>=<span class="string">"geo:*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-navigation</span> <span class="attr">href</span>=<span class="string">"http://*/*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-navigation</span> <span class="attr">href</span>=<span class="string">"https://*/*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-navigation</span> <span class="attr">href</span>=<span class="string">"data:*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">allow-navigation</span> <span class="attr">href</span>=<span class="string">"tel:*"</span> /&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">platform</span> <span class="attr">name</span>=<span class="string">"android"</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">allow-intent</span> <span class="attr">href</span>=<span class="string">"market:*"</span>/&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">icon</span> <span class="attr">src</span>=<span class="string">"resources/android/icon/drawable-ldpi-icon.png"</span> <span class="attr">density</span>=<span class="string">"ldpi"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">platform</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">platform</span> <span class="attr">name</span>=<span class="string">"ios"</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">allow-intent</span> <span class="attr">href</span>=<span class="string">"itms:*"</span>/&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">allow-intent</span> <span class="attr">href</span>=<span class="string">"itms-apps:*"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">platform</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">preference</span> <span class="attr">name</span>=<span class="string">"webviewbounce"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">preference</span> <span class="attr">name</span>=<span class="string">"UIWebViewBounce"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">preference</span> <span class="attr">name</span>=<span class="string">"DisallowOverscroll"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">preference</span> <span class="attr">name</span>=<span class="string">"android-minSdkVersion"</span> <span class="attr">value</span>=<span class="string">"16"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">preference</span> <span class="attr">name</span>=<span class="string">"BackupWebStorage"</span> <span class="attr">value</span>=<span class="string">"none"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">preference</span> <span class="attr">name</span>=<span class="string">"SplashScreenDelay"</span> <span class="attr">value</span>=<span class="string">"2000"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">preference</span> <span class="attr">name</span>=<span class="string">"FadeSplashScreenDuration"</span> <span class="attr">value</span>=<span class="string">"2000"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">feature</span> <span class="attr">name</span>=<span class="string">"StatusBar"</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">param</span> <span class="attr">name</span>=<span class="string">"ios-package"</span> <span class="attr">onload</span>=<span class="string">"true"</span> <span class="attr">value</span>=<span class="string">"CDVStatusBar"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">feature</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">plugin</span> <span class="attr">name</span>=<span class="string">"cordova-plugin-device"</span> <span class="attr">spec</span>=<span class="string">"~1.1.2"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">plugin</span> <span class="attr">name</span>=<span class="string">"cordova-plugin-console"</span> <span class="attr">spec</span>=<span class="string">"~1.0.3"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">plugin</span> <span class="attr">name</span>=<span class="string">"cordova-plugin-whitelist"</span> <span class="attr">spec</span>=<span class="string">"~1.2.2"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">plugin</span> <span class="attr">name</span>=<span class="string">"cordova-plugin-splashscreen"</span> <span class="attr">spec</span>=<span class="string">"~3.2.2"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">plugin</span> <span class="attr">name</span>=<span class="string">"cordova-plugin-statusbar"</span> <span class="attr">spec</span>=<span class="string">"~2.1.3"</span>/&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">plugin</span> <span class="attr">name</span>=<span class="string">"ionic-plugin-keyboard"</span> <span class="attr">spec</span>=<span class="string">"~2.2.0"</span>/&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">widget</span>&gt;</span></div></pre></td></tr></table></figure>
<ul>
<li><p>APP ID</p>
<p>  <code>&lt;widget id=&quot;com.example.myapp2&quot; version=&quot;1.0.0&quot;/&gt;</code>定义了APP的ID和版本信息，分别对应着iOS的Bundle ID及Android的Package。</p>
</li>
<li><p>安全配置</p>
<p>  <code>&lt;allow-intent</code> 和 <code>&lt;allow-navigation</code> 定义了APP访问外部数据时的权限定义。</p>
</li>
<li><p>特定平台配置</p>
<p>  <code>&lt;platform name=&quot;android&quot;&gt;</code>节点下定义特定于iOS、Android的配置，如cordova插件配置，资源图标等</p>
</li>
<li><p>Cordova插件参数配置</p>
<p>  <code>&lt;preference name=&quot;SplashScreenDelay&quot; value=&quot;2000&quot;/&gt;</code>节点定义了<code>SplashScreen</code>插件的参数设置</p>
</li>
<li><p>Cordova插件列表</p>
<p>  <code>&lt;plugin name=&quot;cordova-plugin-device&quot; spec=&quot;~1.1.2&quot;/&gt;</code>节点定义了APP对cordova插件的依赖。该依赖及版本当前只支持手动维护。</p>
<p>  因实际开发过程中，<code>plugins</code>目录下的插件通常不会添加到源代码仓库，在构建工程环境时，package.json中的插件列表并不会自动下载。在config.xml中维护好插件依赖及版本后，执行<code>ionic build ios/android</code>时，ionic会自动下载这些依赖的插件。</p>
</li>
</ul>
<h2 id="编译与调试"><a href="#编译与调试" class="headerlink" title="编译与调试"></a>编译与调试</h2><p>对于空白的工程环境（不存在<code>node_modules</code>，<code>plugins</code>和<code>platform</code>目录），需要先安装JS依赖：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install</div></pre></td></tr></table></figure>
<p>JS依赖安装完成后，执行下述命令可以在浏览器中进行开发调试（推荐使用<code>chrome</code>浏览器）:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ionic serve</div></pre></td></tr></table></figure>
<p>需要编译特定的<code>ios</code>或<code>android</code>版本时，执行下述命令（Android SDK环境及Xcode环境需要准备好，参考前述环境篇）：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ionic build android / ios</div></pre></td></tr></table></figure>
<p>以Android为例，编译输出的<code>apk</code>位于：<code>p环境latform/android/build/outputs/apk/android-debug.apk</code></p>
<h3 id="其他调试方式"><a href="#其他调试方式" class="headerlink" title="其他调试方式"></a>其他调试方式</h3><p>Ionic的开发过程大多数时间通过浏览器进行。有时需要测试Native插件时就需要通过模拟器调试或硬件设备调试。模拟器调试针对Android及iOS需要分别配置好模拟器环境即可。</p>
<p>对于硬件设备调试：</p>
<ol>
<li>iOS通过Xcode环境进行； </li>
<li>Android调试时，部署到硬件设备，打开开发者调试功能，通过USB线连接到电脑，输入下述指令即可在android设备上启动APP：</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ionic run android</div></pre></td></tr></table></figure>
<p>然后，在<code>chrome</code>浏览器的地址栏中输入下述指令即可实时调试：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chrome://inspect/#devices</div></pre></td></tr></table></figure>
<p><img src="/images/ionic_chrome_debug.png" alt="Ionic Chrome Debug"></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><ol>
<li>Ionic结合Cordova为Hybrid开发提供了快速便捷的命令行开发工具，熟悉这些工具可以大大提高开发效率。</li>
<li>在命令行输入<code>ionic -v</code>时，看到的版本信息是指<code>Ionic CLI</code>的版本而不是<code>Ionic 2</code>框架的版本。</li>
<li>在下一篇文章中会进一步探讨Ionic 2的具体开发。</li>
</ol>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/APP/" rel="tag"># APP</a>
          
            <a href="/tags/iOS/" rel="tag"># iOS</a>
          
            <a href="/tags/Android/" rel="tag"># Android</a>
          
            <a href="/tags/Cordova/" rel="tag"># Cordova</a>
          
            <a href="/tags/Angular2/" rel="tag"># Angular2</a>
          
            <a href="/tags/Ionic2/" rel="tag"># Ionic2</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/03/05/hybrid-cordova-angular2-ionic2-practice-2/" rel="next" title="Hybrid混合开发实践-Cordova/Angular2/Ionic2-环境(2)">
                <i class="fa fa-chevron-left"></i> Hybrid混合开发实践-Cordova/Angular2/Ionic2-环境(2)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/04/25/web-js-coffeescript/" rel="prev" title="CoffeeScript 详解(转载)">
                CoffeeScript 详解(转载) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2016/03/12/hybrid-cordova-angular2-ionic2-practice-3/"
     data-title="Hybrid混合开发实践-Cordova/Angular2/Ionic2-工程结构(3)"
     data-content=""
     data-url="http://chrisrc.me/2016/03/12/hybrid-cordova-angular2-ionic2-practice-3/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2016/03/12/hybrid-cordova-angular2-ionic2-practice-3/"
           data-title="Hybrid混合开发实践-Cordova/Angular2/Ionic2-工程结构(3)" data-url="http://chrisrc.me/2016/03/12/hybrid-cordova-angular2-ionic2-practice-3/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="chrisrc" />
          <p class="site-author-name" itemprop="name">chrisrc</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">69</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">21</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">162</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/christtrc" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/chrisrc" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
          
        </div>

        
        
          <div class="cc-license motion-element" itemprop="license">
            <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" target="_blank">
              <img src="/images/cc-by-nc-sa.svg" alt="Creative Commons" />
            </a>
          </div>
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#概述"><span class="nav-number">1.</span> <span class="nav-text">概述</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#代码结构"><span class="nav-number">2.</span> <span class="nav-text">代码结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#工程配置"><span class="nav-number">3.</span> <span class="nav-text">工程配置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#package-json"><span class="nav-number">3.1.</span> <span class="nav-text">package.json</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#config-xml"><span class="nav-number">3.2.</span> <span class="nav-text">config.xml</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#编译与调试"><span class="nav-number">4.</span> <span class="nav-text">编译与调试</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#其他调试方式"><span class="nav-number">4.1.</span> <span class="nav-text">其他调试方式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">5.</span> <span class="nav-text">总结</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">
     
      <a href="mailto:chrisrc@qq.com">chrisrc</a> 
    
  </span>
  <span class="author"> &nbsp; QQ: 58122705 </span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"chrisrc"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  








  
  

  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
<script>
(function(){
   var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?ed903ab05fbc5fa64d95e4bfbf3d3a04":"https://jspassport.ssl.qhimg.com/11.0.1.js?ed903ab05fbc5fa64d95e4bfbf3d3a04";
   document.write('<script src="' + src + '" id="sozz"><\/script>');
})();
</script>

  


</body>
</html>
